Due: February
11th, 2009
In computer programming a matrix is
a two dimensional array. An array is a list of data values. A matrix, or two
dimensional arrays, is a list of values that cross two axis and would appear, conceptually,
as a grid. Matrices are used regularly in programming. Computer animation uses
matrix and matrix logic extensively.
Matrix multiplication is part of this.
Matrix multiplication can be defined
in this way:
In
general, we can take the product AB only if the number of columns of A equals
the number of rows of B (so that we can multiply the rows of A by the columns
of B as above). The product AB is then obtained as follows:
·
To obtain the 1,1 entry of AB, multiply Row 1 of A by Column 1
of B.
·
To obtain the 1,2 entry of AB, multiply Row 1 of A by Column 2
of B.
·
To obtain the 1,3 entry of AB, multiply Row 1 of A by Column 3
of B.
. . .
·
To obtain the 2,1 entry of AB, multiply Row 2 of A by Column 1
of B.
·
To obtain the 2,2 entry of AB, multiply Row 2 of A by Column 1
of B.
It
seems quite a complicated procedure at first but after some practice you'll
find you get used to it. Here's a diagram to illustrate it.
and so on. In general,
To obtain the i,j entry of AB,
multiply Row i of A by Column j of B.
Note: The product AB has as many rows as A and as many columns as B.
You are to write a C++ program that will do
the following:
1.
Read
the input from a data file found here, which contains
information on two matrices, one that is a matrix of resources, and one that is
a matrix of models. The two matrices come with labels for each column and row.
·
The
first line of the file contains a single integer which should be stored in a
variable named res_row, the number
of rows in the resource matrix.
·
The
next line of the file contains a single integer which should be stored in a variable
named res_col, the number of columns
in the resource matrix
·
The
third line contains the names of the individual resources, separated by
semicolons. These should be stored in a character array res_headings,
one name per row.
·
The
fourth line contains the names of the individual models, separated by
semicolons. These should be stored in a character array model_headings,
one name per row.
·
The
next ‘res_row’ lines contain the rows of the resource matrix. These
should be stored in a matrix named resource.
·
The
next line of the file contains a single integer which should be stored in a
variable named model_row, the number
of rows in the model matrix.
·
The
next line of the file contains a single integer which should be stored in a
variable named model_col, the number
of columns in the model matrix
·
The
next ‘model_row’ lines contain the rows of the model matrix. This should
be stored as matrix named model.
·
Your
program should be designed to read one set, perform the analysis described
below, and then loop back to read another set until all data has been
processed. You may assume that the maximum number of resources and models is
10, and that the maximum number of characters in a label is 8. Thus you should
#define the constants MAXNUM as 10 and MAXLEN as 9 (which allows for the null
at the end of the names).
3.
Invoke
a function to multiply the two matrices. You get to write this function with
any input/output arguments you want.
4.
Use
tablewrite to output the multiplied
matrix to the output file
5.
No
global variables are allowed!
6.
Make
sure that the program works for any size matrix in the range. The test dataset
I use to check your program will be completely different.
Please make sure that the assignment is
handed in, in accordance with the requirements stated in the syllabus.